home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / HDX_BACK / HDX302.ST / SHIP.S < prev    next >
Encoding:
Text File  |  2001-02-09  |  3.6 KB  |  157 lines

  1. ;+
  2. ;    Park heads on ACSI devices 0..7
  3. ;
  4. ;  11-Sep-1987 lmd    Put in delay so that the bus
  5. ;            doesn't lock up on the "hidden" completion byte
  6. ;            that John's kludge board swallows.
  7. ;
  8. ;  11-Sep-1987 lmd    Added C interface, ship().
  9. ;
  10. ;-
  11.     .include atari
  12.  
  13.     Super                ; get into supervisor mode
  14.     bsr    park_devices        ; park everything
  15.     User                ; back to user mode
  16.     Pterm0                ; and terminate
  17.  
  18.  
  19. ;+
  20. ;  Synopsis:    ship(dev)
  21. ;        short int dev;
  22. ;
  23. ;    Ship the specified device, after a short delay.
  24. ;
  25. ;    Returns:    0 : successful ship
  26. ;        -1: ship failed (timeout, etc.)
  27. ;
  28. ;    Uses:    D0-D2/A0-A2
  29. ;
  30. ;-
  31. _ship::
  32.     link    a6,#0            ; (get ptr to stack frame)
  33.     movem.l    d3-d7/a3-a5,-(sp)    ; save registers
  34.     Super                ; get into supervisor mode
  35. ;
  36. ;  delay a while
  37. ;
  38.     moveq    #40,d1            ; wait 200 milliseconds
  39. .2:    add.l    _hz_200,d1        ;
  40.     cmp.l    _hz_200,d1        ;
  41.     bge.s    .2            ;
  42. ;
  43. ;  "ship" the device
  44. ;
  45.     move.w    8(a6),d7        ; D7 = dev << 5
  46.     lsl.w    #5,d7            ;
  47.     bsr    park_dev        ; park device D7
  48.     sne    d0            ; D0 = 0 or -1
  49.     ext.w    d0            ;    depending on return code
  50.  
  51.     User                ; back to user mode
  52.     movem.l    (sp)+,d3-d7/a3-a5    ; restore registers
  53.     unlk    a6            ; restore frame ptr
  54.     rts                ; ... and return
  55.  
  56.  
  57. ;+
  58. ;  Park ACSI devices 0..7
  59. ;
  60. ;-
  61. park_devices:
  62.     moveq    #0,d7            ; start with dev #0
  63. .1:    bsr    park_dev        ; park device
  64.  
  65.     moveq    #40,d1            ; wait 200 milliseconds
  66. .2:    add.l    _hz_200,d1        ;
  67.     cmp.l    _hz_200,d1        ;
  68.     bge.s    .2            ;
  69.  
  70.     add.b    #$20,d7            ; next devno
  71.     bne    .1            ; (do all eight devs)
  72.     rts
  73.  
  74.  
  75. ;+
  76. ;  park_dev  --  Park device
  77. ;    Passed:    d7.b = ddd00000
  78. ;        ('ddd' is the ACSI device number, 0..7)
  79. ;
  80. ;    Returns:    NE: park failed;
  81. ;        EQ: successful park.
  82. ;
  83. ;    Preserves:    d7.w
  84. ;
  85. ;    Uses:    everything else
  86. ;
  87. ;
  88. ;-
  89. park_dev:
  90.     lea    fifo,a4            ; a4 -> DMA control register
  91.     lea    diskctl,a5        ; a5 -> DMA data register
  92.     st    flock            ; lock up DMA against vblank
  93.  
  94.     move.w    #$088,(a4)        ; select dma bus (not SCR)
  95.  
  96.     move.b    d7,d0            ; setup d0.L with devno+command
  97.     or.b    #%00011011,d0        ; d0.b = devno<<5 .OR. "PARK" command
  98.     swap    d0            ;
  99.     move.w    #$088,d0        ;
  100.     bsr    wcbyte            ; d0.L = DDD11011xxxxxxx010001010
  101.     bne    .ret            ; (punt on timeout)
  102.  
  103.     moveq    #3,d6            ; (count = 4)
  104. .loop:    move.l    #$0000008a,d0        ;
  105.     bsr    wcbyte            ; write it
  106.     bne    .ret            ; (punt on timeout)
  107.     dbra    d6,.loop        ; (loop for more bytes)
  108.  
  109.     move.l    #$0000000a,(a5)        ; write byte 5 (controlByte = $00)
  110.     move.w    #120,d1            ; timeout = 2.0 sec
  111.     bsr    wwait            ; wait for completion
  112.     bne    .ret            ; (punt on timeout)
  113.  
  114.     move.w    #$08a,(a4)        ; select status reg
  115.     move.w    (a5),d0            ; get return code from DMA device
  116.  
  117.     moveq    #2,d1            ; /* ~ 5 millisecond delay */
  118.     add.l    _hz_200,d1        ; /* for slow acsi devices */
  119. .1:    cmp.l    _hz_200,d1        ;
  120.     bge.s    .1            ;
  121.  
  122. ;--- reset DMA, return NE
  123. .ret:    move.w    #$080,(a4)        ; cleanup DMA chip for floppy driver
  124.     sf    flock            ; unlock DMA chip
  125.     rts                ; return
  126.  
  127.  
  128. ;+
  129. ;  wcbyte - write ACSI command byte, wait for IRQ
  130. ;    Passed:    D0.L = command byte and FIFO control
  131. ;            bits 16..23 = command byte,
  132. ;            bits 0..7 = FIFO control bits
  133. ;        a5 -> $ffff8604
  134. ;
  135. ;    Returns:    NE on failure (timeout)
  136. ;        EQ on successful ACK
  137. ;
  138. ;    Uses:    d1
  139. ;
  140. ;-
  141. wcbyte:    move.l    d0,(a5)            ; write WDC, WDL [due to jwt]
  142.  
  143.     moveq    #2,d1            ; /* ~ 5 millisecond delay */
  144.     add.l    _hz_200,d1        ; /* for slow acsi devices */
  145. .1:    cmp.l    _hz_200,d1        ;
  146.     bge.s    .1            ;
  147.  
  148.     moveq    #40,d1            ; wait 200 milliseconds
  149. wwait:    add.l    _hz_200,d1        ; d1 = time to quit at...
  150. .1:    btst.b    #5,gpip            ; disk done?
  151.     beq.w    .ret            ; (yes, return)
  152.     cmp.l    _hz_200,d1        ; timeout?
  153.     bge.s    .1            ; (not yet -- wait some more...)
  154.     moveq    #-1,d1            ; ensure NE (timeout error) return
  155. .ret:    rts
  156.  
  157.